<template>
  <div id="qinfo-list">
    <nav aria-label="breadcrumb" role="navigation">
      <ol class="breadcrumb">
        <li class="breadcrumb-item">
          <router-link to="/tool/qinfos">Q信息</router-link>
        </li>
        <li class="breadcrumb-item active" aria-current="page">列表</li>
        <span class="ms-auto" @click.stop="back()">返回</span>
      </ol>
    </nav>

    <div class="card col-12 px-0">
      <div class="card-body">
        <form class="row">
          <div class="col-1">
            <input
              class="form-control"
              type="text"
              size="8"
              placeholder="请输入编码"
              v-model="pnrNo"
            />
          </div>
          <div class="col-1">
            <input
              class="form-control"
              type="text"
              size="8"
              placeholder="请输入用户名"
              v-model="username"
            />
          </div>
          <div class="col-1">
            <select class="form-select" v-model="qtype">
              <option value="">全部</option>
              <option value="SC">SC</option>
              <option value="KK">KK</option>
            </select>
          </div>
          <div class="col">
            <button type="button" class="btn btn-primary ms-1" @click.stop="search()">
              查找
            </button>
            <button
              type="button"
              class="btn btn-secondary ms-1"
              @click.stop="reset()"
            >
              重置
            </button>

            <router-link to="/tool/qinfo/setting" class="ms-auto btn btn-primary"
              >设置</router-link
            >
          </div>
        </form>
      </div>

      <table class="table table-striped table-sm">
        <thead>
          <tr>
            <th>类型</th>
            <th>用户名</th>
            <th>记录编码</th>
            <th class="hidden-xs-down">联系电话</th>
            <th class="hidden-xs-down"></th>
            <th class="hidden-xs-down">创建时间</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(flight, index) in qinfoes">
            <td>
              {{ flight.qtype }}
            </td>
            <td>{{ flight.username }}</td>
            <td>
              <a
                href="javascript:void(0);"
                :title="flight.qdetail"
                data-bs-toggle="tooltip"
                @click="showPnrDetail(flight.qdetail)"
                >{{ flight.pnrno }}</a
              >
            </td>
            <td class="hidden-xs-down">
              {{ flight.linkphone }}
            </td>
            <td class="hidden-xs-down">
              <span v-if="flight.beManaged === '2'">
                <button class="btn btn-info btn-sm" @click="reInform(index)">
                  再次通知
                </button>
              </span>
            </td>
            <td class="hidden-xs-down">
              {{ flight.createDate }} {{ flight.createTime }}
            </td>
          </tr>
        </tbody>
      </table>
      <div class="card-body">
        <my-pagination
          :row-count="sc.rowCount"
          :page-total="sc.pageTotal"
          :page-no="sc.pageNo"
          @next-page="nextPage"
          @prev-page="prevPage"
          @direct-page="directPage"
        ></my-pagination>
      </div>
    </div>

    <template v-if="detailShowing">
      <div class="col-12 bg-info text-center text-white">
        <span @click="hideDetail()" class="float-start"
          ><i class="fa fa-angle-left fa-2" aria-hidden="true"></i
        ></span>
        编码详情
      </div>
      <div class="card col-12" v-if="pnrDetail != null">
        <div v-html="'<pre>' + pnrDetail + '</pre>'"></div>
      </div>
    </template>
  </div>
</template>

<script>
import MyPagination from "@/components/my-pagination.vue";

import $ from "jquery";

export default {
  name: "QinfoList",
  components: {
    MyPagination,
  },
  data() {
    return {
      detailShowing: false,
      filterShowing: false,
      pnrDetail: "",

      qinfoes: [],
      sc: {
        rowCount: 0,
        pageNo: 1,
        pageSize: 25,
        pageTotal: 0,
      },
      pnrNo: "",
      username: "",
      qtype: "",
    };
  },
  computed: {
    // acityName() {return this.$store.state.searchParams.acityName},
  },
  mounted: function () {
    this.search();
  },
  methods: {
    back: function () {
      this.$router.go(-1);
    },
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    showLoading: function (loadingText) {
      this.$store.commit("showLoading", {
        loading: true,
        loadingText: loadingText,
      });
    },
    hideLoading: function () {
      this.$store.commit("showLoading", { loading: false });
    },
    search: function () {
      var self = this;
      self.showLoading();

      $.ajax({
        type: "post",
        url: "/Flight/qinfoes/",
        data: {
          "sc.pageNo": self.sc.pageNo,
          "sc.pageSize": self.sc.pageSize,
          "sc.pnrNo": self.pnrNo,
          "sc.username": self.username,
          "sc.qtype": self.qtype,
        },
        dataType: "json",
        success: function (jsonResult) {
          self.qinfoes = jsonResult.dataList;
          self.sc = jsonResult.page;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          self.searching = false;

          if (XMLHttpRequest.status === 403) {
            self.$store.commit("jumpToLogin", self.$router);
          }
        },
        complete: function (XMLHttpRequest, textStatus) {
          self.hideLoading();
        },
      });
    },
    reset: function () {
      this.pnrNo = "";
      this.username = "";
      this.qtype = "";
    },
    reInform: function (index) {
      var id = this.qinfoes[index].id;
      var self = this;

      $.ajax({
        type: "post",
        url: "/Flight/qinfoes/reInformQinfo.do",
        data: { id: id },
        dataType: "json",
        success: function (jsonResult) {
          if (jsonResult.status === "OK") {
            self.search();
          } else {
            self.showErrMsg("操作失败");
          }
        },
      });
    },
    prevPage: function () {
      this.sc.pageNo = this.sc.pageNo - 1;
      if (this.sc.pageNo < 1) this.sc.pageNo = 1;
      this.search();
    },
    nextPage: function () {
      this.sc.pageNo = this.sc.pageNo + 1;
      this.search();
    },
    directPage: function (pageNo) {
      this.sc.pageNo = pageNo;
      this.search();
    },
  },
};
</script>
